﻿using Client.ICommandNotify;
using Client.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Client.ViewModel
{
    public class MainViewModel: NotifyBase
    {
        private Dictionary<string, object> CacheView { get; set; } = new Dictionary<string, object>();

        public List<MenuMode> MenuMode_ { get; set; } = new List<MenuMode>();

        public MainViewModel()
        {
            MenuMode_.Add(new MenuMode()
            {
                IsDetail = false,
                Name = "工程",
                MenuName= "Projcet",
                Items = new List<MenuMode>()
                {
                   new MenuMode()
                   {
                        IsDetail = true,
                        Name = "工程常见问题",
                        MenuName="Projcet.RoutineView"
                   }
                }
            });

            MenuMode_.Add(new MenuMode()
            {
                IsDetail = false,
                Name = "物资",
                MenuName = "Material",
                Items = new List<MenuMode>()
                {
                   new MenuMode()
                   {
                        IsDetail = true,
                        Name = "物资常见问题",
                        MenuName="Material.MaterialView"
                   }
                }
            });

            MenuMode_.Add(new MenuMode()
            {
                IsDetail = false,
                Name = "合同",
                MenuName = "CBM",
                Items = new List<MenuMode>()
                {
                   new MenuMode()
                   {
                        IsDetail = true,
                        Name = "查询合同金额",
                        MenuName="CBM.CBMView"
                   }
                }
            });
            MenuMode_.Add(new MenuMode()
            {
                IsDetail = false,
                Name = "周材",
                MenuName = "Revolve",
                Items = new List<MenuMode>()
                {
                   new MenuMode()
                   {
                        IsDetail = true,
                        Name = "周材采购结算税额差额",
                        MenuName="Revolve.RevolveView"
                   }
                }
            });
            MenuMode_.Add(new MenuMode()
            {
                IsDetail = false,
                Name = "设备",
                MenuName = "Equip",
                Items = new List<MenuMode>()
                {
                   new MenuMode()
                   {
                        IsDetail = true,
                        Name = "设备常见问题",
                        MenuName="Equip.EquipView"
                   }
                }
            });    
            MenuMode_.Add(new MenuMode()
            {
                IsDetail = false,
                Name = "招标",
                MenuName = "Tender",
                Items = new List<MenuMode>()
                {
                   new MenuMode()
                   {
                        IsDetail = true,
                        Name = "招标常见问题",
                        MenuName="Tender.TenderView"
                   }
                }
            });
            MenuMode_.Add(new MenuMode()
            {
                IsDetail = true,
                Name = "数据查询",
                MenuName = "QueryTableView",
            });
            MenuMode_.Add(new MenuMode()
            {
                IsDetail = true,
                Name = "单据反写",
                MenuName = "BillNoAuditAfterView",
            });
            MenuMode_.Add(new MenuMode()
            {
                IsDetail = true,
                Name = "金蝶传入日志",
                MenuName = "BasicQuerySendToKdView",
            });
            MenuMode_.Add(new MenuMode()
            {
                IsDetail = true,
                Name = "Sql语句查询",
                MenuName = "SqlQuery",
            });
            MenuMode_.Add(new MenuMode()
            {
                IsDetail = true,
                Name = "附件",
                MenuName = "Base_Attachment",
            });
            command = new Command(NavigationDoExecute, NavigationCanExecute);
        }
        #region 方法
        private bool NavigationCanExecute()
        {
            return !string.IsNullOrWhiteSpace(this.NameText);
        }

        private void NavigationDoExecute(object obj)
        {
            if (string.IsNullOrWhiteSpace(obj as string)) return;
            Type type = Type.GetType($"Client.View.{obj}");
            if (CacheView.ContainsKey(type.FullName))
            {
                Homepage=CacheView[type.FullName];
                return;
            }
              CacheView.Add(type.FullName, type.Assembly.CreateInstance(type.FullName));
              Homepage = CacheView[type.FullName];
        }
        #endregion
        #region 命令
        public Command command { get; set; }
        #endregion
        #region 属性
        private object Homepage_;

        public object Homepage
        {
            get { return Homepage_; }
            set { Homepage_ = value;
                SetProperty(ref NameText_, NameText);
            }
        }

        private string NameText_="123";

        public string NameText
        {
            get { 
                return NameText_;     
            }
            set { 
                NameText_ = value;
                SetProperty(ref NameText_, NameText);
            }
        }

        #endregion
    }
}
